﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Diagnostics;
using System.Configuration;
using System.IO;

public partial class ProResultUpload : System.Web.UI.Page
{
    protected string ProID
    {
        get
        {
            if (Request.QueryString["ProID"] == null)
            {
                return string.Empty;
            }
            else
            {
                return Request.QueryString["ProID"];
            }
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        this.lab_PID.Text = ProID;
    }
    //上传文件
    protected void btn_Upload_Click(object sender, EventArgs e)
    {
        if (string.IsNullOrEmpty(ProID))
        {
            Frame.Global.GlobalFunctions.Alert("无项目编号！");
            return;
        }
        if (this.FileUpload.HasFile)
        {
            string filename = this.FileUpload.FileName;
            if (WebHelper.IsAllowableFileType(filename))
            {
                string path = "/ResultFiles";
                string localpath = Server.MapPath(Request.ApplicationPath + path);
                string fullPath = localpath + "\\" + filename;
                this.FileUpload.SaveAs(fullPath);
                string swfPath = localpath + "\\" + lab_PID.Text + ".swf";
                this.ConvertToSWF(fullPath, swfPath);
            }
            else
            {
                WebHelper.Alert("文件格式错误，请选择.doc文件！", 1);
            }
        }
    }

    public void ConvertToSWF(string oldFile, string swfFile)
    {
        //FlashPaper文件安装路径 可自行设置
        string flashPrinter = Server.MapPath(".") + "\\FlashPaper\\FlashPrinter.exe";
        Process pss = new Process();

        //删除旧文件
        if (File.Exists(swfFile))
        {
            File.Delete(swfFile);
        }

        pss.StartInfo.CreateNoWindow = false;
        pss.StartInfo.FileName = flashPrinter;
        pss.StartInfo.Arguments = string.Format("{0} {1} -o {2}", flashPrinter, oldFile, swfFile);
        try
        {
            pss.Start();
            while (!pss.HasExited)
            {
                continue;
            }
            if (Frame.Global.GlobalSqlHelper.ExecuteSQL("update ProjectDetails set ProResultFile='" + ProID + ".swf' where Project_ID='" + ProID + "'"))
            {
                
                WebHelper.Alert("恭喜,文件上传成功！", 4);
            }
            else
            {
               WebHelper.Alert("文件上传失败，请重试！", 5);
            }

        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
}